package com.java1412.order.controller;

import com.java1412.common.entity.Goods;
import com.java1412.order.service.GoodsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author java1412
 * @since 2024-01-15 15:48:50
 */
@RestController
@RequestMapping("/api/v1/goods_order")
public class OrderController {

//    @Resource
//    private RestTemplate restTemplate;
//
//    @RequestMapping(value = "/getGoods")
//    public Object save(Integer goodsId) {
//        // return restTemplate.getForObject("http://localhost:6001/api/v1/goods/findByGoodsId?goodsId=" + goodsId, Goods.class);
//        return restTemplate.getForObject("http://mall-goods/api/v1/goods/findByGoodsId?goodsId=" + goodsId, Goods.class);
//    }

    @Resource
    private GoodsService goodsService;

    @RequestMapping(value = "/getGoodsByFeign")
    public Object getGoodsByFeign(
            Integer goodsId
    ) {
        return goodsService.findByGoodsId(goodsId);
    }

    @RequestMapping("/getClusterName")
    public String findClusterName() {
        for (int i = 0; i < 10; i++) {
            System.out.println(goodsService.findClusterName());
        }
        return "执行结束";
    }

    @RequestMapping("/test1")
    public String test1() {
        System.out.println("转发到订单微服务");
        return "order";
    }
}
